<?php
    require_once "weixin_info.php"; //å¾®ä¿¡æŽˆæƒèŽ·å–ç”¨æˆ·å¤´åƒç­‰ä¿¡æ?
    require_once "config.php";
    $id = empty($_GET['id']) ? '' : $_GET['id'];
    $u_id = empty($_GET['u_id']) ? '' : $_GET['u_id'];
    if (empty($id)) {
      header("location:shopping.php");
    }
    $goods_sql = $mysql->query("select * from dyspw_goods where id=" . $id); //è§†é¢‘
    $goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
    $shop_info = $mysql->query("select * from dyspw_member where id=" . $goods[0]['u_id']);
    $shop = $shop_info->fetch_all(MYSQLI_ASSOC);
    if(!empty($shop)){
        $waimai_sql =$mysql->query("select * from dyspw_shop_waimai where  uid = {$shop[0]['id']} ");
        $waimai = $waimai_sql->fetch_all(MYSQLI_ASSOC);
        if(!empty($waimai)){
            //小计金额
            $Subtotal = $goods[0]['group_money'] + $waimai[0]['pack_fee'] + $waimai[0]['delivery_fee'];
            $wmstart_time = $waimai[0]['start_time'];
            $wmend_time = $waimai[0]['end_time'];
        }
    }else{
        header("location:shopping.php");
    }
    // print_r($goods);
    $start_time = strtotime(date("Y-m-d", time()));
    $end_time = strtotime(date("Y-m-d", strtotime("+1 month")));
    $sql = $mysql->query("select * from dyspw_mem_address where  uid = {$_SESSION['Member_info'][0]['id']} ");
    $address_list = $sql->fetch_all(MYSQLI_ASSOC);

?>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <title>订单确定</title>
  <script src="js/mui.min.js"></script>
  <link href="css/mui.min.css" rel="stylesheet" />
  <link href="css/goods_order.css" rel="stylesheet" />
  <script src="js/layer/layer.js" type="text/javascript"></script>
  <script src="js/dsbridge.js" type="text/javascript"></script>
  <script type="text/javascript" charset="utf-8">
    mui.init();
  </script>
  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>
</head>

<body>
<style>
    .hideBox{display: none}
    .onShow{display: block}
    .numberBox{position: absolute;right: 0;bottom:3px;width: 100%;text-align: right}
    .numberBox p{text-align: center;width: 20px;line-height: 20px;float: right;color: #fff!important;background: #ff8c14;border-radius: 50%}
    .numberBox span{display: block;width:20px;line-height: 20px;float: right;margin: 0 3px;text-align: center;
        padding: 0!important;background: #fff!important;color: #333!important;}
    .container .phone-konw{padding:0}
    .container .phone-konw h4{line-height: 32px;margin: 0;float: left}
    .phone-konw input{padding: 0 5px; height: 32px;margin-bottom: 0}
    .phone-konw p{float: right;width: 60%}
    .youji{height: auto;overflow: hidden}
    .youji .phone-konw{display: none;height: auto;overflow: hidden}
    .song img{display: block;width: 100%;height:60px;margin-bottom: 10px}
    .song img.on{border: 1px solid red}
</style>

    <!-- <?php //if(empty($waimai) || $waimai[0]['state'] != 1){ ?>
        此商户不支持外卖配送提示信息
    <?php //} ?>
    <?php //if(checkIsBetweenTime($wmstart_time,$wmend_time)){ ?>
        此商户不在营业时间范围内
    <?php //} ?> -->
    <!-- 后台提供商户经纬度半径，前端判定是否在半径内
    商户经纬度： <?php //echo $waimai[0]['shop_lat']; ?>
    配送半径： <?php //echo $waimai[0]['radius'] ?>     -->




  <div class="container takeaway" id="main-container">
    <div class="navbar waimai" id="navbar">
      <div class="navbar-title" style="height: auto;overflow: hidden">
        <div class="has-border" id="waimai">外卖</div>
        <div class="no-border" id="tuangou">团购</div>
      </div>
      <div class="navbar-content-waimai">
        <div class="navbar-content-list first-content" id="address-select">
          <p class="select" id="address-name">选择地址</p>
          <input type="hidden" name="add_id" id="address-id" value="">
          <input type="hidden" name="add_lat" id="address-lat" value="">
          <input type="hidden" name="add_lng" id="address-lng" value="">
          <span class="mui-icon mui-icon-arrowright"></span>
        </div>
        <p id="address-local"></p>
      <div class="navbar-content-tuangou">
        <div class="navbar-content-local">
          <h5>星巴克咖啡（苏州中心店）</h5>
          <p>4.5km</p>
        </div>
        <p>苏州中心商场北区3层</p>
      </div>
    </div>

    <div class="content">
      <p class="contane-title"><?php echo $goods[0]['u_name'] ?></p>
      <div class="detail" style="position: relative">
        <div class="detail-flex">
          <img src="<?php echo $goods[0]['img']; ?>" />
          <div>
            <h4><?php echo $goods[0]['title']; ?></h4>
            <p id="ajax-number">X 1</p>
          </div>
        </div>
        <div>
          <h5>￥ <?php echo $goods[0]['group_money']; ?>  </h5>
            <div class="numberBox">
                <p class="add" onclick="addNum(this)">+</p>
                <div class="hideBox">
                    <span>1</span>
                    <p class="del" onclick="delNum(this)">-</p>
                </div>
            </div>
        </div>
      </div>

        <?php if($goods[0]['is_give']){?>
            <p class="contane-title">请选择赠送商品</p>
            <div class="song">
             <img class="on" src="<?php echo $goods[0]['img']; ?>" />
             <img src="<?php echo $goods[0]['img']; ?>" />
             <img src="<?php echo $goods[0]['img']; ?>" />
             <img src="<?php echo $goods[0]['img']; ?>" />
             <input type="hidden" name="song" value="0" />
            </div>
        <?php }?>


      <div class="detail-list is-waimai">
        <h5>包装费</h5>
        <p>￥ <?php echo $waimai[0]['pack_fee']; ?></p>
      </div>
      <div class="detail-list is-waimai match_fee">
        <h5>配送费</h5>
        <p>￥<?php echo $waimai[0]['delivery_fee']; ?></p>
      </div>
      <div class="detail-list">
        <h5 class="detail-rule"><span class="is-waimai">优惠规则？</span></h5>
      </div>
    </div>

    <div class="phone">
      <div class="phone-check">
        <p class="phone-protect"><img src="images/icon_call.png" />号码保护</p>
        <div class="mui-switch mui-switch-mini" id="phone-swtich">
          <div class="mui-switch-handle"></div>
        </div>
      </div>
      <p class="phone-tip1">对商家、骑手隐藏您的真实手机号码，保护您的隐私</p>
      <p class="phone-tip2">为保障服务质量，开启号码保护的订单通话可能会被录音</p>
    </div>

    <div class="remarks">
      <div id="remarks-select" class="select-detail">
        <h5>备注</h5>
        <label>
            <p id="remarks-detail">口味，偏好等要求</p>
            <span class="mui-icon mui-icon-arrowright"></span>
        </label>
      </div>
      <div id="tableware-select" class="select-detail">
        <h5>餐具数量</h5>
        <label>
            <p id="tableware-detail">未选择</p>
            <span class="mui-icon mui-icon-arrowright"></span>
        </label>
      </div>
      <div class="submit">
          <input type="hidden" name="reckon_price" value=" <?php echo $goods[0]['group_money']; ?>">
          <input type="hidden" name="reckon_packing" value="<?php echo $waimai[0]['pack_fee']; ?>">
          <input type="hidden" name="reckon_match" value="">
        <p style="color:#fff;">合计:￥<span><?php echo $Subtotal; ?></span></p>
        <p class="sumbit-pay" style="color:#fff;">确认支付</p>
      </div>
    </div>

    <div class="need-know">
      <p class="need-know-title">购买需知</p>
      <div class="need-know-content">
        <div class="need-know-content-title">
          <p>有效期</p>
          <p>使用时间</p>
        </div>
        <div class="need-know-content-detail">
          <p><?php echo date("Y-m-d"); ?>至 <?php echo date('Y-m-d',strtotime("+1 month")); ?>      </p>
          <p>10:00-21:00</p>
        </div>
      </div>
      <div class="phone-konw">
          <h4>手机号码</h4>
          <p  style="width: 60%;"><input id="phone-konw" type="text" name="mobile" value="" style="width:100%;"/></p>
      </div>

     <div class="youji">
        <div class="phone-check" style="height: auto;overflow: hidden">
            <p class="phone-protect" style="float: left;line-height: 28px;margin: 0">配送方式</p>
                <div class="" style="    display: inline-block;float: right;font-size: 14px;color: #bbb;">
                <label ><input type="radio" name="is_youji"   value="hexiao" style="position: relative;top: 2px;"/>到店核销</label>
                <label style="margin-left:10px;"><input type="radio" name="is_youji"   value="youji" style="position: relative;top: 2px;"/>邮寄配送</label>
            </div>
        </div>
        <div class="" style="clear: both" style="margin-top: 10px;">
             <textarea name="tuangou_beizhu" class="tuangou_beizhu" rows="8" cols="80" placeholder="备注" maxlength=200 style="height: 100px;width: 100%"></textarea>
        </div>
        <div class="phone-konw" style="clear: both">
             <h4>联系人</h4>
             <p style="width: 60%;"><input id="phone-konw" type="text" name="link_man" value="" autocomplete="off" style="width:100%;"/></p>
        </div>

        <div class="phone-konw" style="margin-top: 0">
             <h4>邮寄地址</h4>
             <p  style="width: 60%;"><input id="phone-konw" type="text" name="link_address" value="" autocomplete="off"   style="width:100%;"/></p>
        </div>
     </div>

      <div class="submit">
        <p style="color:#fff;">合计:￥<span id="money" class="group_money"><?php $Subtotal=$goods[0]['group_money']; echo
                $Subtotal;
        ?></span></p>
        <p class="sumbit-pay" style="color:#fff;">确认支付</p>
      </div>
    </div>



  </div>

  <div id="address-popover" class="mui-popover address-list">
    <div class="address-list-title">
    <!-- <i class="mui-icon mui-icon-closeempty" id="close-pop"></i> --!>
      <p>地址选择</p>
    </div>
    <ul class="mui-table-view mui-table-view-radio" style="overflow-y: auto;">
        <?php foreach ($address_list as $key => $val) { ?>
            <li class="mui-table-view-cell" onclick="changeaddress('<?php echo $val['add_place'] ?>', '<?php echo $val['add_brand'] ?>', '<?php echo $val['id'] ?>','<?php echo $val['add_lat'] ?>','<?php echo $val['add_lng'] ?>');" >
                <a class="mui-navigate-right">
                    <p><?php echo $val['add_place'] ?></p>
                    <p><?php echo $val['add_brand'] ?></p>
                    <h5><?php echo $val['add_link'] ?><?php if($val['add_sex'] == 1){echo '(先生)';}else{echo '(女士)';} ?><?php echo $val['add_mobile']; ?></h5>
                </a>
            </li>
        <?php } ?>
        <li> <a href="address_edit.php" style="display: inline-block;width: 150px;height: 30px;background: #8D97B1;line-height: 30px;text-align: center;margin: 20px 0px;font-size: 14px;position: relative;left: 50%;transform: translateX(-50%);border-radius: 5px;color: #fff;">添加地址</a> </li>
    </ul>
  </div>

  <div id="remarks-popover" class="mui-popover remarks-pop address-list">
  <!-- <div class="remarks-list-title">
       <p class="remarks-pop-title">备注</p>
      <a class="close-remarks" id="close-remarks">确定</a>
     </div> -->
    <div class="address-list-title">
      <i class="mui-icon mui-icon-closeempty" id="close-remarks"></i>
      <p>备注</p>
    </div>
    <textarea name="txtarea" onblur="changeReamrk(this)" id="txtarea" rows="5" cols="10" placeholder="备注信息"></textarea>
  </div>

  <div id="tableware-popover" class="mui-popover address-list">
  <div class="address-list-title">
  <!--  <i class="mui-icon mui-icon-closeempty" id="close-tableware"></i> -->
      <p>餐具选择</p>
    </div>
   <div class="tableware-list">
    <p onclick="changetableware('tableware-one', '无需餐具')"
    id="tableware-one">无需餐具<br/>
     <span>(筷子，刀，勺，吸管）</span>
    </p>
    <p onclick="changetableware('tableware-two', '1份')" id="tableware-two">1份</p>
    <p onclick="changetableware('tableware-three', '2份')" id="tableware-three">2份</p>
    <p onclick="changetableware('tableware-four', '3份')" id="tableware-four">3份</p>
    <p onclick="changetableware('tableware-five', '4份')" id="tableware-five">4份</p>
    <p onclick="changetableware('tableware-six', '5份')" id="tableware-six">5份</p>
   </div>
  </div>

  <script>
    window.onload = function(){
      var input1 = document.querySelector('#phone-konw')
      input1.oninput = function(e){
        input1.value = input1.value.replace(/\D/g,'')
        console.log(input1.value)
      }
    }
  </script>
  <script src="./js/jquery-2.2.4.min.js"></script>
  <!-- <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> -->
  <script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.1&key=fedad41056b27c3e8cc5eaca216434e9"></script>
  <script>

      //添加商品
      function addNum(e){
          var rob = '<?php echo $goods[0]['rob'] ?>';
          if(rob == 'rob'){
              layer.open({
                  content: '特价商品只能限购一份哦',
                  skin: 'msg',
                  time: 3
              });
              return;
          }
          var hideBox=$(e).parent().find('.hideBox');
          if(!hideBox.hasClass('onShow')){
              hideBox.addClass('onShow')
          }
          var num=hideBox.find('span').html();
          num ++;
          commonSet(hideBox,num,true);
      }

      //删除商品
      function delNum(e){
          var num=$(e).parent().find('span').html();
          num --;
          if(num == 1){
              $(e).parent().removeClass('onShow');
          }
          commonSet($(e).parent(),num,false);
      }

      //设置商品总金额
      function commonSet(e,num,status){
          $(e).parent().find('span').html(num);
          var price='<?php echo $goods[0]['group_money']?>';
          money=Number(price) * num;
          $(".group_money").html(money)
      }

    //   function youji(e) {
    //     if($(e).hasClass('mui-active')){
    //          $(".youji .phone-konw").show();
    //     }else {
    //         $(".youji .phone-konw").hide();
    //     }
    //   }
    $("input[name='is_youji']").change(function(){
        var is_youji = $("input[name='is_youji']:checked").val();
        if(is_youji == 'youji'){
            $(".youji .phone-konw").show();
        }else{
            $(".youji .phone-konw").hide();
        }
    })





    // 重新选择地址
      function changeaddress(name, address,id,lat,lng) {
        $("#address-name")[0].innerText = name;
        $("#address-local")[0].innerText = address;
        $("#address-id").val(id);
        $("#address-lat").val(lat);
        $("#address-lng").val(lng);
        mui('#address-popover').popover('toggle', document.getElementById("openPopover"));
        var url = '/order/price/';
        var shop_id = '<?php echo $waimai[0]['id']; ?>';
        var param = {'dispatch_mode':1,'shop_id':shop_id,'receiver_longitude':lng,'receiver_latitude':lat,'receiver_address':address};
        $.ajax({
            url: "shipping.php",
            type: "post",
            data: {'url':url, 'param':param},
            dataType: 'JSON',
            success: function(res) {
                res = JSON.parse(res);
                if(res.code == 1){
                    $("input[name='reckon_match']").val(ret.data.min_price);
                    $(".match_fee p").html("￥"+ret.data.min_price);
                    totai_price()
                }else{
                    layer.open({
                        content: res.message,
                        skin: 'msg',
                        time: 3
                    });
                    $("#address-id").attr('value','');
                }
            }
        })
      }

      function totai_price(){
          var reckon_match = $("input[name='reckon_match']").val();
          var reckon_price = $("input[name='reckon_price']").val();
          var reckon_packing = $("input[name='reckon_packing']").val();
          var total = reckon_match*1+reckon_price*1+reckon_packing*1;
          console.log(total);
          $(".submit p span").html(total);
          $(".detail-all span").html("￥"+total);
      }

      // 餐具选择
      function changetableware(id, text) {
        $("#tableware-one")[0].className = "";
        $("#tableware-two")[0].className = "";
        $("#tableware-three")[0].className = "";
        $("#tableware-four")[0].className = "";
        $("#tableware-five")[0].className = "";
        $("#tableware-six")[0].className = "";
        $("#" + id)[0].className = "tableware-active";
        $("#tableware-detail")[0].innerText = text;
        mui('#tableware-popover').popover('toggle', document.getElementById("openPopover"));
      }

      function changeReamrk(e) {
        if (e.value) {
          $("#remarks-detail")[0].innerText = e.value;
        } else {
          $("#remarks-detail")[0].innerText = '口味，偏好等要求';
        }
      }

    (function() {
      if ('<?php empty($waimai) ?>' || '<?php echo $waimai[0]['state'] != 1 ?>') {
        layer.open({
            content: "此商户不支持外卖配送",
            skin: 'msg',
            time: 3
        });
        $("#navbar")[0].className = 'navbar tuangou';
        $("#main-container")[0].className = 'container group';
    } else if (false) {
        layer.open({
            content: "此商户不在营业时间范围内",
            skin: 'msg',
            time: 3
        });
        $("#navbar")[0].className = 'navbar tuangou';
        $("#main-container")[0].className = 'container group';
      }
    })()

    $(function() {

        $(".song img").click(function () {
           $(this).addClass('on').siblings().removeClass('on');
           $(this).parent().find('input').val($(this).index());
        });


      // 选择外卖
      $("#waimai").click(function() {
        if ('<?php empty($waimai) ?>' || '<?php echo $waimai[0]['state'] != 1 ?>') {
        layer.open({
            content: "此商户不支持外卖配送",
            skin: 'msg',
            time: 3
        });
    } else if (false) {
        layer.open({
            content: "此商户不在营业时间范围内",
            skin: 'msg',
            time: 3
        });
      } else {
        $("#navbar")[0].className = 'navbar waimai';
        $("#main-container")[0].className = 'container takeaway';
      }
      });

      // 选择团购
      $("#tuangou").click(function() {
        $("#navbar")[0].className = 'navbar tuangou';
        $("#main-container")[0].className = 'container group';
      });

      // 地址选择
      $("#address-select").click(function() {
        mui('#address-popover').popover('toggle', document.getElementById("openPopover"));
      });

      // 关闭选择地址
      $("#close-pop").click(function() {
        mui('#address-popover').popover('toggle', document.getElementById("openPopover"));
      });

      // 餐具选择
      $("#tableware-select").click(function() {
        mui('#tableware-popover').popover('toggle', document.getElementById("openPopover"));
      });

      $("#close-tableware").click(function() {
        mui('#tableware-popover').popover('toggle', document.getElementById("openPopover"));
      });

      // 备注
      $("#remarks-select").click(function() {
        mui('#remarks-popover').popover('toggle', document.getElementById("openPopover"));
      });

      $("#close-remarks").click(function() {
        mui('#remarks-popover').popover('toggle', document.getElementById("openPopover"));
      });

      //表单提交
      $(".sumbit-pay").click(function() {
        var order_type = $("#main-container")[0].className === "container takeaway" ? "waimai" : "group";
        var number = parseInt($(".numberBox").find('span').html());
        if(order_type == 'waimai'){
            var money = '<?php echo $Subtotal; ?>';
        }else {
            var money = $(".group_money").html();
        }
        if(order_type == 'waimai'){
            var remarks = $("#remarks-detail")[0].innerText === '口味，偏好等要求' ? '' : $("#remarks-detail")[0].innerText;// 备注
        }else{
            var remarks = $(".tuangou_beizhu").val();
        }
        var mobile = $("#phone-konw").val();
        var start_time = '<?php echo $start_time; ?>';
        var end_time = '<?php echo $end_time; ?>';
        var goods_id = '<?php echo  $goods[0]['id']; ?>';
        var shop_id = '<?php echo $shop[0]['id']; ?>';
        var add_id = $("#address-id").val();
        var reckon_match = $("input[name='reckon_match']").val();//配送费
        var reckon_price = $("input[name='reckon_price']").val();//单价
        var reckon_packing = $("input[name='reckon_packing']").val();//包装费
        var mobile_is = $("#phone-swtich")[0].className === "mui-switch mui-switch-mini mui-active";// 是否号码保护
        var meal_num = parseInt($("#tableware-detail")[0].innerText.slice(0,1));
        var youji  = $("input[name='is_youji']:checked").val();

        var link_man = $("input[name='link_man']").val();
        var link_address = $("input[name='link_address']").val();
        var song = $("input[name='song']").val();
        if(song == '' || song == undefined){song = 0;}
        // alert(youji);return;
        if(youji == '' || youji == undefined){
            layer.open({
              content: '请选择配送方式',
              skin: 'msg',
              time: 2
            });
            return;
        }
        if(youji == 'youji'){
            if(order_type == 'group' && ( link_man == '' || link_address == '')){
                layer.open({
                  content: '请输入联系人或邮寄地址',
                  skin: 'msg',
                  time: 2
                });
                return;
            }
        }
        if(order_type == 'group' && mobile == ''){
            layer.open({
              content: '请输入手机号码',
              skin: 'msg',
              time: 2
            });
            return;
        }
        if (!add_id && order_type === "waimai") {
          layer.open({
            content: '请选择配送地址',
            skin: 'msg',
            time: 2
          });
        } else {
          //提交接口 判断是否APP
          // consol.log(window.navigator.userAgent)
          if(window.navigator.userAgent == 'AndroidNative'){
              // javascript:android.indexShare(_imgURL, title, desc, _link);
              $.ajax({
                url: "./api/appPay.php?action=confirmOrder",
                type: "post",
                data: {
                  "uid": '<?php echo $_SESSION['Member_info'][0]['id'] ?>',
                  'money': money,                 //支付金额
                  'number': number,               //数量
                  'mobile': mobile,               //手机号
                  'remarks': remarks,             //备注
                  'reckon_match' : reckon_match,
                  'reckon_packing' : reckon_packing,
                  'start_time': start_time,       //订单开始时间
                  'end_time': end_time,           //订单结束时间
                  'goods_id': goods_id,           //商品id
                  'shop_id': shop_id,             //店铺id
                  'order_type': order_type,       //订单类型 外卖：waimai ,团购：group
                  'guide_uid': '<?php if(!empty($u_id)){echo $u_id;}?>',
                  'add_id': add_id,               //配送地址id
                  'meal_num': typeof meal_num === 'number' && !isNaN(meal_num) ? meal_num : 0,             //餐具数量
                  'mobile_is': mobile_is,         //号码保护
                  'youji': youji,         //是否邮寄
                  'link_man': link_man,         //邮寄联系人
                  'link_address': link_address,         //邮寄地址
                  'song': song,         //赠送商品ID
                },
                dataType: 'JSON',
                success: function(ret) {
                  if(!ret.code){
                    dsBridge.call("aliPay", {
                      data: ret.data
                    });
                  }else{
                    alert(ret.message)
                  }
                }
              })
          } else if (window.navigator.userAgent == 'IosNative') {
              // window.webkit.messageHandlers.indexShare.postMessage({img: _imgURL, title: title, content:desc, link:_link});
              $.ajax({
                url: "./api/appPay.php?action=confirmOrder",
                type: "post",
                data: {
                    "uid": '<?php echo $_SESSION['Member_info'][0]['id'] ?>',
                  'money': money,                 //支付金额
                  'number': number,               //数量
                  'mobile': mobile,               //手机号
                  'remarks': remarks,             //备注
                  'reckon_match' : reckon_match,
                  'reckon_packing' : reckon_packing,
                  'start_time': start_time,       //订单开始时间
                  'end_time': end_time,           //订单结束时间
                  'goods_id': goods_id,           //商品id
                  'shop_id': shop_id,             //店铺id
                  'order_type': order_type,       //订单类型 外卖：waimai ,团购：group
                  'guide_uid': '<?php if(!empty($u_id)){echo $u_id;}?>',
                  'add_id': add_id,               //配送地址id
                  'meal_num': typeof meal_num === 'number' && !isNaN(meal_num) ? meal_num : 0,             //餐具数量
                  'mobile_is': mobile_is,         //号码保护
                    'youji': youji,         //是否邮寄
                    'link_man': link_man,         //邮寄联系人
                    'link_address': link_address,         //邮寄地址
                    'song': song,         //赠送商品ID
                },
                dataType: 'JSON',
                success: function(ret) {
                  if(!ret.code){
                    dsBridge.call("aliPay", {
                      data: ret.data
                    });
                  }else{
                    alert(ret.message)
                  }
                }
              })
          } else {
              // loadData();
              $.ajax({
                url: "goods_payment.php",
                type: "post",
                data: {
                  'money': money,                 //支付金额
                  'number': number,               //数量
                  'mobile': mobile,               //手机号
                  'remarks': remarks,             //备注
                  'reckon_match' : reckon_match,
                  'reckon_packing' : reckon_packing,
                  'start_time': start_time,       //订单开始时间
                  'end_time': end_time,           //订单结束时间
                  'goods_id': goods_id,           //商品id
                  'shop_id': shop_id,             //店铺id
                  'order_type': order_type,       //订单类型 外卖：waimai ,团购：group
                  'guide_uid': '<?php if(!empty($u_id)){echo $u_id;}?>',
                  'add_id': add_id,               //配送地址id
                  'meal_num': typeof meal_num === 'number' && !isNaN(meal_num) ? meal_num : 0,             //餐具数量
                  'mobile_is': mobile_is,         //号码保护
                    'youji': youji,         //是否邮寄
                    'link_man': link_man,         //邮寄联系人
                    'link_address': link_address,         //邮寄地址
                    'song': song,         //赠送商品ID
                },
                dataType: 'JSON',
                success: function(ret) {
                  if (ret.status == 'y') {
                    WeixinJSBridge.invoke(
                      'getBrandWCPayRequest', {
                        "appId": ret.data.appId,
                        "timeStamp": ret.data.timeStamp,
                        "nonceStr": ret.data.nonceStr,
                        "package": ret.data.package,
                        "signType": ret.data.signType,
                        "paySign": ret.data.paySign,
                      },
                      function(ret) {
                        if (ret.err_msg == "get_brand_wcpay_request:cancel") {
                          layer.open({
                            content: "您已取消了此次支付",
                            skin: 'msg',
                            time: 3
                          });
                        } else if (ret.err_msg == "get_brand_wcpay_request:fail") {
                          layer.open({
                            content: "支付失败，请重新尝试",
                            skin: 'msg',
                            time: 3
                          });
                        } else if (ret.err_msg == "get_brand_wcpay_request:ok") {
                          layer.open({
                            content: "支付成功,等待审核",
                            skin: 'msg',
                            time: 3
                          });
                          location.href = 'order_list.php'; //跳转支付成功页面
                        } else {
                          layer.open({
                            content: "未知错误" + ret.err_msg,
                            skin: 'msg',
                            time: 3
                          });
                        }
                      }
                    );
                  } else {
                    return layer.open({
                      content: ret.info,
                      skin: 'msg',
                      time: 3
                    });
                  }
                }
              })
          }
        }
      })

    })
  </script>
</body>

</html>
